package com.woniuxy.config;

import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

/**
 * @author Leimin
 * @date 2022/05/06 15:22
 **/
@Configuration
public class ValidatorConfig {

    //配置验证器
    @Bean
    public Validator validator() {
        ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class)
                .configure()
                // 快速失败模式，到第一个不满足条件的参数时就立即返回
                .failFast(true)
                .buildValidatorFactory();
        return validatorFactory.getValidator();
    }
}

